/**
 * 
 */
package com.yidu.erp.service.fdannex;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.yidu.common.Tools;
import com.yidu.erp.dao.BeyondAnnexMapper;
import com.yidu.erp.dao.BeyondMoneyMapper;
import com.yidu.erp.model.BeyondAnnex;
import com.yidu.erp.model.BeyondMoney;

/**
 * 分店的service接口
 * @author liao
 *
 */
@Service
public class BeyondAnnexServiceImp implements  BeyondAnnexService{
	
	@Resource
	public BeyondAnnexMapper   BeyondAnnexMapper;
	@Resource
	BeyondMoneyMapper BeyondMoneyMapper;

	@Override
	public BeyondAnnex selectByPrimaryKey(String annexId) {
		
		return BeyondAnnexMapper.selectByPrimaryKey(annexId);
	}

	@Override
	public Map<String, Object> selectAll(Map<String, Object> param) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("data", BeyondAnnexMapper.selectAll(param));
		map.put("count", BeyondAnnexMapper.findAllRowCount(param));
		map.put("code", 0);
		map.put("msg", 0);
		return map;
	}


	@Override
	public int deleteByPrimaryKey(String annexId) {
		return BeyondAnnexMapper.deleteByPrimaryKey(annexId);
	}


	@Override
	public int updateOrAdd(BeyondAnnex annex) {
		int rows = 0;
		if(Tools.isEmpty(annex.getAnnexId())){
			Date date=new Date();
			annex.setAnnexTime(date);
			rows = BeyondAnnexMapper.insertSelective(annex);
			
			BeyondMoney record=new BeyondMoney();
			record.setAnnexId(annex.getAnnexId());
			record.setMoneySummoney(100000);
			record.setMoneyBz("分店");
			BeyondMoneyMapper.insertSelective(record);
		}else{
			annex.setAnnexMoney(5000.0);
			rows = BeyondAnnexMapper.updateByPrimaryKeySelective(annex);
		}
		return rows;
	}

	@Override
	public List<BeyondAnnex> showList() {
		List<BeyondAnnex> list=BeyondAnnexMapper.showList();
		return list;
	}

	@Override
	public BeyondAnnex getAnnexId(String annexName) {
		return BeyondAnnexMapper.getAnnexId(annexName);
	}

}
